Completed
Push — master ( 641a91...fc9f6a )
by
unknown
10:16
created

angular.service(ꞌEncryptServiceꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 36
rs 9.016
c 0
b 0
f 0
nc 1
nop 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 9 2
A ��) 0 13 3
1
/**
2
 * Nextcloud - passman
3
 *
4
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
5
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
(function () {
24
	'use strict';
25
	/**
26
	 * @ngdoc service
27
	 * @name passmanApp.EncryptService
28
	 * @description
29
	 * # EncryptService
30
	 * Service in the passmanApp.
31
	 */
32
	angular.module('passmanApp')
33
		.service('EncryptService', ['VaultService', function (VaultService) {
34
			// AngularJS will instantiate a singleton by calling "new" on this function
35
			var encryption_config = {
36
				adata: "",
37
				iter: 1000,
38
				ks: 256,
39
				mode: 'ccm',
40
				ts: 64
41
			};
42
43
			return {
44
				encryptString: function (string, _key) {
45
					if (!_key) {
46
						_key = VaultService.getActiveVault().vaultKey;
47
					}
48
					var rp = {};
49
					/** global: sjcl */
50
					var ct = sjcl.encrypt(_key, string, encryption_config, rp);
51
					return window.btoa(ct);
52
				},
53
				decryptString: function (ciphertext, _key) {
54
					if (!_key) {
55
						_key = VaultService.getActiveVault().vaultKey;
56
					}
57
					ciphertext = window.atob(ciphertext);
58
					var rp = {};
59
					try {
60
						/** global: sjcl */
61
						return sjcl.decrypt(_key, ciphertext, encryption_config, rp);
62
					} catch (e) {
63
						throw e;
64
					}
65
				}
66
67
			};
68
		}]);
69
}());